package com.example.webserver.controller;


import com.example.webserver.entity.Category;
import com.example.webserver.entity.Result;
import com.example.webserver.service.impl.Categoryserviceimpl;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

@RestController
@RequestMapping("category")
public class Categorycontroller{
    @Autowired
    Categoryserviceimpl categoryservice;

    @PostMapping
    public Result addCategory(@RequestBody  @Valid Category category){
        categoryservice.add(category);
        return Result.success();
    }

    @GetMapping
    public Result<List<Category>> CategoryList(){
        List list=categoryservice.list();
        return Result.success(list);
    }

    @PutMapping
    public Result update(@RequestBody @Valid Category category){
        categoryservice.update(category);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(Integer id){
        categoryservice.delete(id);
        return Result.success();
    }

    @GetMapping("detail")
    public Result<Category> getdetail(int id){
        Category category=categoryservice.findcategorybyId(id);
        return Result.success(category);
    }
}
